import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/product',
    name: 'product',
    component: ()=>import('../views/product/ProductView.vue')
  },
  {
    path: '/test',
    name: 'test',
    component: ()=>import('../views/TestView.vue')
  },
  {
    path: '/cart',
    name: 'cart',
    component: ()=>import('../views/cart/CartView.vue')
  },{
    path: '/login',
    name: 'login',
    component: ()=>import('../views/user/LoginView.vue')
  },{
    path: '/register',
    name: 'register',
    component: ()=>import('../views/user/RegisterView.vue')
  },{
    path: '/profile',
    name: 'profile',
    component: ()=>import('../views/user/ProfileView.vue')
  },
  {
    path: '/orders',
    name: 'orders',
    component: ()=>import('../views/order/OrderView.vue')
  },
  {
    path: '/ordersItem',
    name:'orderItem',
    component: ()=>import('../views/order/OrderItemView.vue'),
    props: true, //启用动态路由参数
    meta: {
      title: '订单项详情'
      // requiresAuth: true//需要登录
    }
  }, {
    path: '/orderUser',
    name: 'orderUser',
    component: ()=>import('../views/order/OrderUserView.vue'),
    props: true, //启用动态路由参数
    meta: {
      title: '用户订单'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})
// // 全局前置守卫：阻止重复导航
// router.beforeEach((to, from, next) => {
//   console.log('全局前置守卫：', to, from)
//   next()
// })

export default router
